<template>
    <div class="container-content">
        <el-form
            ref="elForm"
            :model="formObject"
            label-width="100px"
            :rules="rules"
            status-icon
            label-position="left"
        >
            <el-collapse v-model="activeName" @change="handleClick">
                <el-collapse-item title="供应商编码" name="code">
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item
                                label="创建组织"
                                prop="createDeptName"
                            >
                                <el-input
                                    v-model="formObject.createDeptName"
                                    disabled
                                >
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="使用组织" prop="useDeptName">
                                <el-input
                                    v-model="formObject.useDeptName"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="注册编码" prop="registerCode">
                                <el-input
                                    v-model="formObject.registerCode"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item label="编码" prop="supplierCode">
                                <el-input
                                    v-model="formObject.supplierCode"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="名称" prop="supplierName">
                                <el-input
                                    v-model="formObject.supplierName"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="简称" prop="forShort">
                                <el-input
                                    v-model="formObject.forShort"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-collapse-item>
                <el-collapse-item title="基本信息" name="basic">
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item label="国家" prop="nationId">
                                <el-select
                                    v-model="formObject.nationId"
                                    placeholder="请选择国家"
                                    style="width: 100%"
                                    @change="changeNation"
                                >
                                    <el-option
                                        v-for="item in nationData"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="地区" prop="provincesId">
                                <el-select
                                    v-model="formObject.provincesId"
                                    placeholder="请选择地区"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in provincesData"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="通讯地址"
                                prop="mailingAddress"
                            >
                                <el-input
                                    v-model="formObject.mailingAddress"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="邮政编码" prop="zipCode">
                                <el-input
                                    v-model="formObject.zipCode"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="语言" prop="language">
                                <el-select
                                    v-model="formObject.language"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in languageOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="公司网址"
                                prop="companyWebsite"
                            >
                                <el-input
                                    v-model="formObject.companyWebsite"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item label="行业" prop="industryName">
                                <el-input v-model="formObject.industryName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('industry')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="创立日期" prop="establishDate">
                                <el-date-picker
                                    v-model="formObject.establishDate"
                                    type="date"
                                    placeholder="选择日期"
                                    style="width: 100%"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="法人代表"
                                prop="legalRepresentative"
                            >
                                <el-input
                                    v-model="formObject.legalRepresentative"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="注册资金"
                                prop="registeredCapital"
                            >
                                <el-input
                                    v-model="formObject.registeredCapital"
                                    placeholder="万元"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="工商登记号"
                                prop="registrationNumber"
                            >
                                <el-input
                                    v-model="formObject.registrationNumber"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="生产经营许可证"
                                prop="productionLicense"
                                label-width="120px"
                            >
                                <el-input
                                    v-model="formObject.productionLicense"
                                ></el-input>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item
                                label="注册地址"
                                prop="companyRegisteredAddress"
                            >
                                <el-input
                                    v-model="
                                        formObject.companyRegisteredAddress
                                    "
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="统一社会信用代码"
                                prop="creditCode"
                                label-width="130px"
                            >
                                <el-input
                                    v-model="formObject.creditCode"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item
                                label="负责部门"
                                prop="chargeDeptName"
                            >
                                <el-input v-model="formObject.chargeDeptName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('dept')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="负责人"
                                prop="chargePersonName"
                            >
                                <el-input v-model="formObject.chargePersonName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('person')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="供应商分类"
                                prop="classification"
                            >
                                <el-select
                                    v-model="formObject.classification"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in classificationOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="供应类别"
                                prop="supplyCategory"
                            >
                                <el-select
                                    v-model="formObject.supplyCategory"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in supplyCategoryOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="供应商等级" prop="level">
                                <el-select
                                    v-model="formObject.level"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in levelOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="供应商分组" prop="groupName">
                                <el-input v-model="formObject.groupName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('group')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="公司类别"
                                prop="companyCategory"
                            >
                                <el-select
                                    v-model="formObject.companyCategory"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in companyCategoryOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="公司性质" prop="companyNature">
                                <el-select
                                    v-model="formObject.companyNature"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in companyNatureOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="公司规模" prop="companySize">
                                <el-select
                                    v-model="formObject.companySize"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in companySizeOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item
                                label="对应集团供应商"
                                prop="groupSupplierName"
                                label-width="140px"
                            >
                                <el-input
                                    v-model="formObject.groupSupplierName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('supplier')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="集团供应商" prop="">
                                <el-checkbox
                                    :true-value="true"
                                    :false-value="false"
                                ></el-checkbox>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-collapse-item>
                <el-collapse-item title="商务信息" name="business">
                    <el-row :gutter="20">
                        <el-col :span="6">
                            <el-form-item
                                label="采购组"
                                prop="purchaseGroupName"
                            >
                                <el-input
                                    v-model="formObject.purchaseGroupName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('purchase')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="默认价目表"
                                prop="defaultPriceListName"
                            >
                                <el-input
                                    v-model="formObject.defaultPriceListName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('price')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="业务状态" prop="businessState">
                                <el-input
                                    v-model="formObject.businessState"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="默认折扣表"
                                prop="defaultDiscountName"
                            >
                                <el-input
                                    v-model="formObject.defaultDiscountName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('discount')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="冻结范围" prop="freezeScope">
                                <el-input
                                    v-model="formObject.freezeScope"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="供货方" prop="supplyName">
                                <el-input v-model="formObject.supplyName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('supply')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="冻结人" prop="freezingPerson">
                                <el-input
                                    v-model="formObject.freezingPerson"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="汇总公司"
                                prop="summaryCompanyName"
                            >
                                <el-input
                                    v-model="formObject.summaryCompanyName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('summary')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="冻结日期" prop="freezeDate">
                                <el-date-picker
                                    disabled
                                    v-model="formObject.freezeDate"
                                    type="date"
                                    placeholder="选择日期"
                                    style="width: 100%"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="保证金比例" prop="ensureRate">
                                <el-input
                                    v-model="formObject.ensureRate"
                                    placeholder="%"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="默认联系人"
                                prop="defaultContracts"
                            >
                                <el-input
                                    v-model="formObject.defaultContracts"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="20">
                        <el-col :span="6">
                            <el-form-item label="VMI仓库" prop="vmiWarehouse">
                                <el-input
                                    :disabled="!formObject.isVmi"
                                    v-model="formObject.vmiWarehouse"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="VMI业务" prop="isVmi">
                                <el-checkbox v-model="formObject.isVmi" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="启用供应商协同"
                                prop="enableCoordination"
                                label-width="110px"
                            >
                                <el-checkbox
                                    v-model="formObject.enableCoordination"
                                />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-collapse-item>

                <el-collapse-item title="财务信息" name="financial">
                    <el-row :gutter="20">
                        <el-col :span="6">
                            <el-form-item
                                label="对应客户"
                                prop="correspondingCustomerName"
                            >
                                <el-input
                                    v-model="
                                        formObject.correspondingCustomerName
                                    "
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('customer')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="单次预付额度"
                                prop="singlePrepaymentLimit"
                            >
                                <el-input
                                    v-model="formObject.singlePrepaymentLimit"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="发票类型" prop="invoiceType">
                                <el-select
                                    v-model="formObject.invoiceType"
                                    filterable
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in invoiceTypeOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="结算币别"
                                prop="balanceCurrencyName"
                            >
                                <el-input
                                    v-model="formObject.balanceCurrencyName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('currency')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="税分类" prop="taxType">
                                <el-select
                                    v-model="formObject.taxType"
                                    filterable
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in taxTypeOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="默认税率"
                                prop="defaultTaxName"
                            >
                                <el-input v-model="formObject.defaultTaxName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('tax')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="结算方式"
                                prop="balanceMethodName"
                            >
                                <el-input
                                    v-model="formObject.balanceMethodName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('balance')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="税务登记号" prop="taxNumber">
                                <el-input
                                    v-model="formObject.taxNumber"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="付款条件"
                                prop="paymentTermsName"
                            >
                                <el-input v-model="formObject.paymentTermsName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('payment')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="经营类型" prop="manageType">
                                <el-select
                                    v-model="formObject.manageType"
                                    filterable
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in manageTypeOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item
                                label="结算方"
                                prop="balancePartyName"
                            >
                                <el-input v-model="formObject.balancePartyName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('party')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="收款方" prop="payeeName">
                                <el-input v-model="formObject.payeeName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="openDialog('payee')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="描述" prop="desc">
                                <el-input
                                    v-model="formObject.desc"
                                    type="textarea"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-button
                        type="text"
                        size="medium"
                        @click="addNewRow('banks')"
                        >新增行</el-button
                    >
                    <el-table
                        :data="formObject.banks"
                        style="width: 100%"
                        highlight-current-row
                        border
                    >
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button
                                    plain
                                    icon="el-icon-minus"
                                    size="mini"
                                    @click="
                                        handleDataDelete(
                                            scope.$index,
                                            scope.row,
                                            'banks'
                                        )
                                    "
                                ></el-button>
                            </template>
                        </el-table-column>
                        <el-table-column label="开户国家" width="170">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="openingCountry"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-select
                                        v-model="scope.row.openingCountry"
                                        placeholder="请选择开户国家"
                                        style="width: 100%"
                                    >
                                        <el-option
                                            v-for="item in openingCountryData"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="银行账号">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="bankAccount"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.bankAccount"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="账户名称">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="accountName"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.accountName"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <!--  -->
                        <el-table-column label="收款银行">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="dueBanke"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.dueBanke"
                                        clearable
                                        disabled
                                    ></el-input>
                                </el-form-item>
                                <!-- @change="
                                        positionChange(
                                            scope.row.position,
                                            scope.$index
                                        )
                                    " -->
                            </template>
                        </el-table-column>
                        <el-table-column label="网点名称">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="brancheName"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.brancheName"
                                        clearable
                                        disabled
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="银行网点">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="bankBranches"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input v-model="scope.row.bankBranches">
                                        <!-- <i
                                          slot="suffix"
                                          class="el-input__icon el-icon-notebook-2"
                                          style="cursor: pointer"
                                          @click="openDialog('bankBranches')"
                                      ></i> -->
                                    </el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="开户行地址">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="openBankAddress"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.openBankAddress"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="开户银行">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="bankName"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.bankName"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="银联号">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="unionPayAccount"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.unionPayAccount"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="币别">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="currencyName"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.currencyName"
                                        clearable
                                    >
                                        <i
                                            slot="suffix"
                                            class="el-input__icon el-icon-notebook-2"
                                            style="cursor: pointer"
                                            @click="
                                                openDialog(
                                                    'bankCurrency',
                                                    scope.$index
                                                )
                                            "
                                        ></i>
                                    </el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="是否默认">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="isDefault"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-checkbox
                                        v-model="scope.row.isDefault"
                                        :true-value="true"
                                        :false-value="false"
                                    />
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="描述">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="desc"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.desc"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-collapse-item>
                <el-collapse-item title="联系人" name="more">
                    <el-button
                        type="text"
                        size="medium"
                        @click="addNewRow('contracts')"
                        >新增行</el-button
                    >
                    <el-table
                        :data="formObject.contracts"
                        style="width: 100%"
                        highlight-current-row
                        border
                    >
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button
                                    plain
                                    icon="el-icon-minus"
                                    size="mini"
                                    @click="
                                        handleDataDelete(
                                            scope.$index,
                                            scope.row,
                                            'contracts'
                                        )
                                    "
                                ></el-button>
                            </template>
                        </el-table-column>
                        <el-table-column label="编码">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="code"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.code"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="联系人" width="150">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="name"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input v-model="scope.row.name">
                                    </el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="性别">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="sex"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-select
                                        v-model="scope.row.sex"
                                        placeholder="请选择"
                                        style="width: 100%"
                                    >
                                        <el-option
                                            key="0"
                                            label="男"
                                            value="0"
                                        ></el-option>
                                        <el-option
                                            key="1"
                                            label="女"
                                            value="1"
                                        ></el-option>
                                        <el-option
                                            key="2"
                                            label="未知"
                                            value="2"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="职位">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="position"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.position"
                                    ></el-input>
                                    <!-- @change="
                                        positionChange(
                                            scope.row.position,
                                            scope.$index
                                        )
                                    " -->
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="电话">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="workTel"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.workTel"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="手机">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="mobile"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.mobile"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="传真">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="fax"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.fax"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="电子邮箱">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="email"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.email"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="默认联系人">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="isDefault"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-checkbox
                                        v-model="scope.row.isDefault"
                                        :true-value="true"
                                        :false-value="false"
                                    />
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="所属公司">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="belongCompany"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.belongCompany"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="详细地址">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="address"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.address"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-collapse-item>
                <el-collapse-item title="组织信息" name="org">
                    <el-button
                        type="text"
                        size="medium"
                        @click="addNewRow('org')"
                        >新增行</el-button
                    >
                    <el-table
                        :data="formObject.organizations"
                        style="width: 100%"
                        highlight-current-row
                        border
                    >
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button
                                    plain
                                    icon="el-icon-minus"
                                    size="mini"
                                    @click="
                                        handleDataDelete(
                                            scope.$index,
                                            scope.row,
                                            'org'
                                        )
                                    "
                                ></el-button>
                            </template>
                        </el-table-column>
                        <el-table-column label="编码">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="locationCode"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.locationCode"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="">
                            <template slot="header">
                                地点名称<span class="required">*</span>
                            </template>
                            <template slot-scope="scope">
                                <el-form-item
                                    label-width="0px"
                                    style="margin: 0"
                                    :rules="rules.locationName"
                                    :prop="
                                        'organizations.' +
                                        scope.$index +
                                        '.locationName'
                                    "
                                >
                                    <el-input
                                        v-model="scope.row.locationName"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="">
                            <template slot="header">
                                联系人<span class="required">*</span>
                            </template>
                            <template slot-scope="scope">
                                <el-form-item
                                    label-width="0px"
                                    style="margin: 0"
                                    :rules="rules.contractsName"
                                    :prop="
                                        'organizations.' +
                                        scope.$index +
                                        '.contractsName'
                                    "
                                >
                                    <el-input
                                        v-model="scope.row.contractsName"
                                        clearable
                                    >
                                        <i
                                            slot="suffix"
                                            class="el-input__icon el-icon-notebook-2"
                                            style="cursor: pointer"
                                            @click="
                                                openDialog(
                                                    'contracts',
                                                    scope.$index
                                                )
                                            "
                                        ></i>
                                    </el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="">
                            <template slot="header">
                                通讯地址<span class="required">*</span>
                            </template>
                            <template slot-scope="scope">
                                <el-form-item
                                    label-width="0px"
                                    style="margin: 0"
                                    :rules="rules.mailingAddress"
                                    :prop="
                                        'organizations.' +
                                        scope.$index +
                                        '.mailingAddress'
                                    "
                                >
                                    <el-input
                                        v-model="scope.row.mailingAddress"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="启用">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="isEnable"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-radio-group
                                        v-model="scope.row.isEnable"
                                    >
                                        <el-checkbox
                                            v-model="scope.row.isEnable"
                                        />
                                    </el-radio-group>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="电话">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="workTel"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.workTel"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="">
                            <template slot="header">
                                手机<span class="required">*</span>
                            </template>
                            <template slot-scope="scope">
                                <el-form-item
                                    label-width="0px"
                                    style="margin: 0"
                                    :rules="rules.orgMobile"
                                    :prop="
                                        'organizations.' +
                                        scope.$index +
                                        '.mobile'
                                    "
                                >
                                    <el-input
                                        v-model="scope.row.mobile"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="传真">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="fax"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.fax"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="电子邮箱">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="email"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.email"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="备注">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="remark"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.remark"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="默认供货地址">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="isDefaultSupply"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-radio-group
                                        v-model="scope.row.isDefaultSupply"
                                    >
                                        <el-checkbox
                                            v-model="scope.row.isDefaultSupply"
                                        />
                                    </el-radio-group>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="默认开票地址">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="isDefaultInvoicing"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-radio-group
                                        v-model="scope.row.isDefaultInvoicing"
                                    >
                                        <el-checkbox
                                            v-model="
                                                scope.row.isDefaultInvoicing
                                            "
                                        />
                                    </el-radio-group>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="默认收款地址">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="isDefaultPayment"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-radio-group
                                        v-model="scope.row.isDefaultPayment"
                                    >
                                        <el-checkbox
                                            v-model="scope.row.isDefaultPayment"
                                        />
                                    </el-radio-group>
                                </el-form-item>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-collapse-item>
                <el-collapse-item title="其他信息" name="other">
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item label="创建人" prop="userId">
                                <el-input
                                    disabled
                                    v-model="formObject.userId"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="审核人" prop="examineId">
                                <el-input
                                    disabled
                                    v-model="formObject.examineId"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="禁用人" prop="disabledId">
                                <el-input
                                    disabled
                                    v-model="formObject.disabledId"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="创建日期" prop="establishDate">
                                <el-date-picker
                                    disabled
                                    v-model="formObject.establishDate"
                                    type="date"
                                    placeholder="选择日期"
                                    style="width: 100%"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="审核日期" prop="examineTime">
                                <el-date-picker
                                    disabled
                                    v-model="formObject.examineTime"
                                    type="date"
                                    placeholder="选择日期"
                                    style="width: 100%"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="禁用日期" prop="disabledDate">
                                <el-date-picker
                                    disabled
                                    v-model="formObject.disabledDate"
                                    type="date"
                                    placeholder="选择日期"
                                    style="width: 100%"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="修改人" prop="changeId">
                                <el-input
                                    disabled
                                    v-model="formObject.changeId"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="数据状态" prop="dataState">
                                <el-input
                                    disabled
                                    v-model="formObject.dataState"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="禁用状态" prop="disabledState">
                                <el-input
                                    disabled
                                    v-model="formObject.disabledState"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="修改日期" prop="changeTime">
                                <el-date-picker
                                    disabled
                                    v-model="formObject.changeTime"
                                    type="date"
                                    placeholder="选择日期"
                                    style="width: 100%"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-collapse-item>
            </el-collapse>
        </el-form>
        <!-- 弹窗 -->
        <el-dialog
            :title="dialogTitle"
            :visible.sync="open"
            append-to-body
            width="50%"
            destroy-on-close
        >
            <component
                :is="currentCom"
                :id="rowId"
                :deptLevel="deptLevel"
                :type="type"
                :visible.sync="open"
                @getSelectVal="getSelectVal"
            ></component>

            <span slot="footer" class="dialog-footer">
                <el-button @click="cancelSelect">取 消</el-button>
                <el-button type="primary" @click="confirmSelect"
                    >确 定</el-button
                >
            </span>
        </el-dialog>
    </div>
</template>
<script>
import { getAreaList } from "@/api/area/area";
import { getInfo } from "@/api/login";
import { getTaxData, getCurrencyData, getPayData } from "@/api/base/data";
import { saveSupply, submitSupply } from "@/api/system/supply";

import Dept from "@/components/dialog/dept";
import Industry from "@/components/dialog/industry";
import Contacts from "@/components/dialog/contacts";
import Currency from "@/components/dialog/currency";
import SettlementType from "@/components/dialog/settlementType";
import PaymentType from "@/components/dialog/paymentTerms";
import TaxRate from "@/components/dialog/taxRate";
import Customer from "@/components/dialog/customer";
import Supplier from "@/components/dialog/supplier";
import PriceInfo from "@/components/dialog/priceinfoId";
import BusinessGroup from "@/components/dialog/businessGroup";
import SupplierGroup from "@/components/dialog/supplierGroup";
import User from "@/components/dialog/user";
import SupplierContacts from "@/components/dialog/supplierContact";
export default {
    components: {
        Dept,
        Industry,
        Contacts,
        Currency,
        SettlementType,
        PaymentType,
        TaxRate,
        Customer,
        Supplier,
        PriceInfo,
        BusinessGroup,
        SupplierGroup,
        User,
        SupplierContacts,
    },
    data() {
        return {
            activeName: [
                "code",
                "basic",
                "business",
                "other",
                "financial",
                "more",
                "org",
            ],
            open: false,
            loading: true,
            dialogType: "",
            counties: [],
            limit: 10,
            page: 1,
            total: 0,
            rowId: "",
            deptLevel: "",
            type: 0,
            dialogTitle: "",
            listIndex: 0,
            selectItem: [],
            orgData: [], //创建组织弹窗列表
            deptData: [], //部门弹窗列表
            personData: [], //负责人弹窗列表
            groupData: [], //供应商弹窗列表
            supplyData: [], //对应集团供应商 供货方 汇总公司 弹窗列表
            purchaseData: [], //采购组弹窗列表
            priceData: [], //默认价目表 默认折扣表 弹窗列表
            customerData: [], //对应客户表 弹窗列表
            taxData: [], //默认税率 弹窗列表
            balanceData: [], //结算方式 弹窗列表
            currencyData: [], //结算币别 弹窗列表
            contractsData: [], //联系人 弹窗列表
            paymentData: [], //付款条件 弹窗列表

            formObject: {
                balanceCurrency: "",
                balanceCurrencyName: "",
                balanceMethod: "",
                balanceMethodCode: "",
                balanceMethodName: "",
                balanceParty: "",
                balancePartyName: "",
                banks: [],
                businessState: "",
                changeId: "",
                changeTime: "",
                chargeDept: "",
                chargeDeptCode: "",
                chargeDeptName: "",
                chargePerson: "",
                chargePersonName: "",
                cityId: "",
                classification: "",
                companyCategory: "",
                companyNature: "",
                companyRegisteredAddress: "",
                companySize: "",
                companyWebsite: "",
                contracts: [],
                correspondingCustomer: "",
                correspondingCustomerName: "",
                correspondingOrganization: "",
                countyId: "",

                createDept: "",
                createDeptName: "",
                createTime: "",
                creditCode: "",
                dataState: "",
                defaultContracts: "",
                defaultDiscount: "",
                defaultDiscountName: "",
                defaultPriceList: "",
                defaultPriceListName: "",
                defaultTax: "",
                defaultTaxName: "",
                desc: "",
                disabledDate: "",
                disabledId: "",
                disabledState: "",
                enableCoordination: false,
                ensureRate: "",
                establishDate: this.parseTime(new Date()),
                examineId: "",
                examineTime: "",
                forShort: "",
                freezeDate: "",
                freezeScope: "",
                freezingPerson: "",
                group: "",
                groupCode: "",
                groupName: "",
                groupSupplier: "",
                groupSupplierCode: "",
                groupSupplierName: "",
                id: "",
                industry: "",
                industryName: "",
                invoiceType: "",
                isVmi: false,
                language: "",
                legalRepresentative: "",
                level: "",
                mailingAddress: "",
                manageType: "",
                nationId: "",
                organizations: [],
                payee: "",
                payeeName: "",
                paymentTerms: "",
                paymentTermsName: "",
                productionLicense: "",
                provincesId: "",
                provincesName: "",
                purchaseGroup: "",
                purchaseGroupName: "",
                registerCode: "",
                registeredCapital: "",
                registrationNumber: "",
                singlePrepaymentLimit: "",
                summaryCompany: "",
                summaryCompanyName: "",
                supplierCode: "",
                supplierName: "",
                supply: "",
                supplyName: "",
                supplyCategory: "",
                taxNumber: "",
                taxType: "",
                useDept: "",
                useDeptName: "",
                userId: "",
                vmiWarehouse: "",
                zipCode: "",
                businessType: "41",
                modelId: this.$store.state.workflow.businessConfig.id,
            },
            // 组织信息
            orgObj: {
                changeTime: "",
                contractsId: "",
                contractsName: "",
                createTime: "",
                email: "",
                fax: "",
                id: "",
                isDefaultInvoicing: true,
                isDefaultPayment: true,
                isDefaultSupply: true,
                isEnable: true,

                locationCode: "",
                locationName: "",
                mailingAddress: "",
                phone: "",
                remark: "",
                supplierId: "",
                tel: "",
                userId: "",
            },
            // 联系人
            contractsObj: {
                address: "",
                addressCode: "",
                addressName: "",
                belongCompany: "",
                changeTime: "",
                contactsCode: "",
                createTime: "",
                email: "",
                fax: "",
                id: "",
                isDefault: true,

                mobile: "",
                name: "",
                position: "",
                sex: "",
                supplierId: "",
                type: "",
                userId: "",
                workTel: "",
            },
            // 银行
            banksObj: {
                accountName: "",
                addAndTel: "",
                bankAccount: "",
                bankBranches: "",
                bankName: "",
                brancheName: "",
                changeTime: "",
                createBy: "",
                createTime: "",
                currency: "",
                desc: "",
                dueBanke: "",
                id: "",
                invoicingCompanyName: "",
                isDefault: "",

                openBankAddress: "",
                openingCountry: "",
                params: {},
                relationId: "",
                remark: "",
                searchValue: "",
                swiftCode: "",
                taxId: "",
                type: 0,
                unionPayAccount: "",
                updateBy: "",
                updateTime: "",
            },
            //发票类型
            invoiceTypeOptions: [],
            // 语言
            languageOptions: [
                {
                    value: "1",
                    label: "中文",
                },
                {
                    value: "2",
                    label: "英文",
                },
            ],

            // 公司类别
            companyCategoryOptions: [],
            // 公司性质
            companyNatureOptions: [],
            // 公司规模
            companySizeOptions: [],
            // 税分类
            taxTypeOptions: [],
            // 经营类型
            manageTypeOptions: [],

            rules: {
                createDeptName: [
                    { required: true, message: "", trigger: "blur" },
                ],
                useDeptName: [
                    {
                        required: true,
                        message: "",
                        trigger: "blur",
                    },
                ],
                supplierName: [
                    { required: true, message: "请输入名称", trigger: "blur" },
                ],
                balanceCurrencyName: [
                    {
                        required: true,
                        message: "请输入结算币别",
                        trigger: "blur",
                    },
                ],
                locationName: [
                    {
                        required: true,
                        message: "请输入地点名称",
                        trigger: "blur",
                    },
                ],
                contractsName: [
                    {
                        required: true,
                        message: "请选择联系人",
                        trigger: "blur",
                    },
                ],
                mailingAddress: [
                    {
                        required: true,
                        message: "请输入通讯地址",
                        trigger: "blur",
                    },
                ],
                orgMobile: [
                    {
                        required: true,
                        message: "请输入手机",
                        trigger: "blur",
                    },
                ],
                // customerName: [
                //   { required: true, message: "客户名称不能为空！", trigger: "blur" },
                // ],
                // name: [
                //   { required: true, message: "联系人姓名不能为空！", trigger: "blur" },
                // ],
            },
            nationData: [], // 国家下拉
            provincesData: [], // 地区下拉
            classificationOptions: [], //供应商分类
            supplyCategoryOptions: [], //供应商类别
            levelOptions: [], //供应商等级
            openingCountryData: [], //开户国家
        };
    },
    methods: {
        // 页签切换事件
        handleClick(tab, event) {
            console.log(tab, event);
        },
        // 附件上传
        handleFileChange() {
            console.log("文件上传");
        },
        // 选择弹窗 item
        getSelectVal(val, isDbleclick) {
            this.selectItem = val;
            if (isDbleclick) {
                this.confirmSelect();
            }
        },
        // 提交
        submit() {
            const cb = (res) => {
                const obj = {
                    id: res.data,
                    businessType: "41",
                    modelId: this.$store.state.workflow.businessConfig.id,
                };
                submitSupply(obj).then((res) => {
                    if (res.code === 200) {
                        this.$store.commit(
                            "workflow/SET_BUSINESSDRAWER",
                            false
                        );
                        this.$message({
                            message: "提交成功！",
                            type: "success",
                        });
                    }
                });
            };
            this.temporaryStorage(cb);
        },
        // 暂存
        temporaryStorage(cb) {
            this.$refs["elForm"].validate((valid) => {
                if (!valid) {
                    this.$message.error("请填写完整信息！");
                    return;
                }
                // TODO 提交表单
                saveSupply(this.formObject).then((res) => {
                    if (res.code === 200) {
                        if (cb) {
                            cb(res);
                            return;
                        }
                        this.$store.commit(
                            "workflow/SET_BUSINESSDRAWER",
                            false
                        );
                        this.$message({
                            message: "暂存成功！",
                            type: "success",
                        });
                    }
                });
            });
        },
        // 基础表单取消
        formRest(basicFormRef) {
            this.$refs[basicFormRef].resetFields();
        },
        // 联系人表单 添加行
        handleDataAdd() {
            if (this.formObject.contracts == undefined) {
                this.formObject.contracts = [];
            }
            let obj = {
                address: "",
                addressCode: "",
                addressName: "",
                belongCompany: "",
                changeTime: "",
                contactsCode: "",
                createTime: "",
                email: "",
                fax: "",
                id: "",
                isDefault: true,

                mobile: "",
                name: "",
                position: "",
                sex: "",
                supplierId: "",
                type: "",
                userId: "",
                workTel: "",
            };
            this.formObject.contracts.push(obj);
        },
        // 删除行
        handleDataDelete(index, row, type) {
            this.$confirm("请确认是否要删除此行？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.$message({
                        type: "success",
                        message: "删除成功!",
                    });
                    if (type == "org") {
                        this.formObject.organizations.splice(index, 1);
                    } else if (type == "banks") {
                        this.formObject.banks.splice(index, 1);
                    } else {
                        this.formObject.contracts.splice(index, 1);
                    }
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },
        //银行信息表单 添加行
        handleDataAdd_banks() {
            if (this.formObject.banks == undefined) {
                this.formObject.banks = [];
            }
            let obj = {
                accountName: "",
                addAndTel: "",
                bankAccount: "",
                bankBranches: "",
                bankName: "",
                brancheName: "",
                changeTime: "",
                createBy: "",
                createTime: "",
                currency: "",
                currencyName: "",
                desc: "",
                dueBanke: "",
                id: "",
                invoicingCompanyName: "",
                isDefault: "",

                openBankAddress: "",
                openingCountry: "",
                params: {},
                relationId: "",
                remark: "",
                searchValue: "",
                swiftCode: "",
                taxId: "",
                type: 0,
                unionPayAccount: "",
                updateBy: "",
                updateTime: "",
            };
            let parentId = 0;
            getAreaList({ parentId }).then((res) => {
                if (res.code === 200) {
                    this.openingCountryData = res.rows.map((item) => {
                        return {
                            value: item.id,
                            label: item.areaName,
                        };
                    });
                }
            });
            getCurrencyData().then((res) => {
                obj.currency = res.rows[0].code;
                obj.currencyName = res.rows[0].currencyName;
            });
            this.formObject.banks.push(obj);
        },

        //组织表单 添加行
        handleDataAdd_org() {
            if (this.formObject.organizations == undefined) {
                this.formObject.organizations = [];
            }
            let obj = {
                changeTime: "",
                contractsId: "",
                contractsName: "",
                createTime: "",
                email: "",
                fax: "",
                id: "",
                isDefaultInvoicing: true,
                isDefaultPayment: true,
                isDefaultSupply: true,
                isEnable: true,

                locationCode: "",
                locationName: "",
                mailingAddress: "",
                phone: "",
                remark: "",
                supplierId: "",
                tel: "",
                userId: "",
            };
            this.formObject.organizations.push(obj);
        },

        //添加新行
        addNewRow(type) {
            if (type === "org") {
                this.handleDataAdd_org();
            } else if (type === "banks") {
                this.handleDataAdd_banks();
            } else {
                this.handleDataAdd();
            }
        },

        // 创建组织 弹窗
        selectOrg() {
            this.dialogTitle = "选择组织";
            this.currentCom = Dept;
            this.deptLevel = 1;
        },

        // 国家弹窗
        getNation() {
            let parentId = 0;
            getAreaList({ parentId }).then((res) => {
                if (res.code === 200) {
                    this.nationData = res.rows.map((item) => {
                        return {
                            value: item.id,
                            label: item.areaName,
                        };
                    });
                }
            });
        },
        // 选择国家
        changeNation(val) {
            if (val) {
                let level = 1;
                getAreaList({ level }).then((res) => {
                    if (res.code === 200) {
                        this.provincesData = res.rows.map((item) => {
                            return {
                                value: item.id,
                                label: item.areaName,
                            };
                        });
                    }
                });
            }
        },
        //负责部门 弹窗
        selectDept() {
            this.dialogTitle = "选择部门";
            this.currentCom = Dept;
            this.deptLevel = 2;
        },
        // 负责人 弹窗
        selectPerson() {
            this.dialogTitle = "选择负责人";
            this.currentCom = User;
        },
        // 供应商分组 弹窗
        selectGroup() {
            this.dialogTitle = "选择供应商分组";
            this.currentCom = SupplierGroup;
        },

        // 采购组 弹窗
        selectPurchase() {
            this.dialogTitle = "选择采购组";
            this.currentCom = BusinessGroup;
        },
        // 默认价目表 默认折扣表
        selectPrice() {
            // 处理弹出框标题
            const typeArray = {
                price: () => {
                    this.dialogTitle = "选择默认价目";
                    this.currentCom = PriceInfo;
                    this.type = 0;
                },
                discount: () => {
                    this.dialogTitle = "选择默认折扣";
                    this.currentCom = PriceInfo;
                    this.type = 1;
                },
            };
            typeArray[this.dialogType] ? typeArray[this.dialogType]() : "";
        },
        // 对应集团供应商 供货方 汇总公司  收款方 结算方
        selectSupply() {
            // 处理弹出框标题
            const typeArray = {
                supplier: () => {
                    this.dialogTitle = "选择供应商";
                },
                supply: () => {
                    this.dialogTitle = "选择供货方";
                },
                summary: () => {
                    this.dialogTitle = "选择汇总公司";
                },
                payee: () => {
                    this.dialogTitle = "选择收款方";
                },
                party: () => {
                    this.dialogTitle = "选择结算方";
                },
            };
            typeArray[this.dialogType] ? typeArray[this.dialogType]() : "";
            this.currentCom = Supplier;
        },
        // 对应客户
        selectCustomer() {
            this.dialogTitle = "选择客户";
            this.currentCom = Customer;
        },
        // 默认税率
        selectTax() {
            this.dialogTitle = "选择税率";
            this.currentCom = TaxRate;
        },
        // 付款条件
        selectPayment() {
            this.dialogTitle = "选择付款条件";
            this.currentCom = PaymentType;
        },
        // 结算方式
        selectBalance() {
            this.dialogTitle = "选择结算方式";
            this.currentCom = SettlementType;
        },
        // 结算币别
        selectCurrency() {
            this.dialogTitle = "选择结算币别";
            this.currentCom = Currency;
        },
        // 联系人
        selectContracts() {
            this.dialogTitle = "选择联系人";
            this.currentCom = SupplierContacts;
        },
        // 行业
        selectIndustry() {
            this.dialogTitle = "选择行业";
            this.currentCom = Industry;
        },

        // 打开弹窗
        openDialog(val, index) {
            this.open = true;
            this.loading = true;
            this.dialogType = val;
            this.listIndex = index;
            this.refresh();
        },

        // 弹窗取消按钮
        cancelSelect() {
            this.open = false;
            this.selectItem = [];
        },
        // 弹窗确定按钮
        confirmSelect() {
            this.refresh(this.selectItem);
        },
        // 处理请求
        refresh(val) {
            const nameMap = {
                dept: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.chargeDept = val[0].deptId;
                        this.formObject.chargeDeptCode = val[0].deptCode;
                        this.formObject.chargeDeptName = val[0].deptName;
                        this.open = false;
                    } else {
                        this.selectDept();
                    }
                },
                person: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.chargePerson = val[0].userId;
                        this.formObject.chargePersonName = val[0].userName;
                        this.open = false;
                    } else {
                        this.selectPerson();
                    }
                },
                group: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.group = val[0].id;
                        this.formObject.groupCode = val[0].supplierCode;
                        this.formObject.groupName = val[0].supplierGroup;
                        this.open = false;
                    } else {
                        this.selectGroup();
                    }
                },
                supplier: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.groupSupplier = val[0].id;
                        this.formObject.groupSupplierCode = val[0].supplierCode;
                        this.formObject.groupSupplierName =
                            val[0].supplierGroup;
                        this.open = false;
                    } else {
                        this.selectSupply();
                    }
                },
                purchase: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.purchaseGroup = val[0].id;
                        this.formObject.purchaseGroupName =
                            val[0].businessGroupType;
                        this.open = false;
                    } else {
                        this.selectPurchase();
                    }
                },
                price: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.defaultPriceList = val[0].id;
                        this.formObject.defaultPriceListName = val[0].name;
                        this.open = false;
                    } else {
                        this.selectPrice();
                    }
                },
                supply: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.supply = val[0].id;
                        this.formObject.supplyName = val[0].supplierName;
                        this.open = false;
                    } else {
                        this.selectSupply();
                    }
                },
                summary: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.summaryCompany = val[0].id;
                        this.formObject.summaryCompanyName =
                            val[0].summaryCompany;
                        this.open = false;
                    } else {
                        this.selectSupply();
                    }
                },
                discount: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.defaultDiscount = val[0].id;
                        this.formObject.defaultDiscountName = val[0].name;
                        this.open = false;
                    } else {
                        this.selectPrice();
                    }
                },
                customer: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.correspondingCustomer = val[0].id;
                        this.formObject.correspondingCustomerName =
                            val[0].customerName;
                        this.open = false;
                    } else {
                        this.selectCustomer();
                    }
                },
                payee: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.payee = val[0].id;
                        this.formObject.payeeName = val[0].supplierName;
                        this.open = false;
                    } else {
                        this.selectSupply();
                    }
                },
                tax: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.defaultTax = val[0].rate;
                        this.formObject.defaultTaxName = val[0].title;
                        this.open = false;
                    } else {
                        this.selectTax();
                    }
                },
                payment: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.paymentTerms = val[0].id;
                        this.formObject.paymentTermsName = val[0].title;
                        this.open = false;
                    } else {
                        this.selectPayment();
                    }
                },
                balance: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.balanceMethod = val[0].id;
                        this.formObject.balanceMethodCode = val[0].bizCode;
                        this.formObject.balanceMethodName = val[0].title;
                        this.open = false;
                    } else {
                        this.selectBalance();
                    }
                },
                currency: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.balanceCurrencyName =
                            val[0].currencyName;
                        this.formObject.balanceCurrency = val[0].code;
                        this.open = false;
                    } else {
                        this.selectCurrency();
                    }
                },
                bankCurrency: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.organizations[this.listIndex].currency =
                            val[0].code;
                        this.formObject.organizations[
                            this.listIndex
                        ].currencyName = val[0].currencyName;
                        this.open = false;
                    } else {
                        this.selectCurrency();
                    }
                },
                party: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.balanceParty = val[0].id;
                        this.formObject.balancePartyName = val[0].supplierName;
                        this.open = false;
                    } else {
                        this.selectSupply();
                    }
                },
                contracts: () => {
                    if (val) {
                        this.formObject.organizations[
                            this.listIndex
                        ].contractsId = val[0].userId;
                        this.formObject.organizations[
                            this.listIndex
                        ].contractsName = val[0].name;
                        this.open = false;
                    } else {
                        this.selectContracts();
                    }
                },
                industry: () => {
                    if (val) {
                        if (val.length !== 1) {
                            this.$message.error("请选择一条记录！");
                            return;
                        }
                        this.formObject.industry = val[0].id;
                        this.formObject.industryName = val[0].title;
                        this.open = false;
                    } else {
                        this.selectIndustry();
                    }
                },
            };
            nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
        },
        // 默认数据请求
        initDefaultData() {
            //  组织
            getInfo().then((res) => {
                this.formObject.createDept = res.deptId;
                this.formObject.createDeptName = res.deptName;
                this.formObject.useDept = res.deptId;
                this.formObject.useDeptName = res.deptName;
            });
            // 结算币别
            getCurrencyData().then((res) => {
                this.formObject.balanceCurrencyName = res.rows[0].currencyName;
                this.formObject.balanceCurrency = res.rows[0].code;
            });
            // 税率
            getTaxData().then((res) => {
                this.formObject.defaultTax = res.rows[0].rate;
                this.formObject.defaultTaxName = res.rows[0].title;
            });
            // 付款条件
            getPayData().then((res) => {
                this.formObject.paymentTerms = res.data.records[0].id;
                this.formObject.paymentTermsName = res.data.records[0].title;
            });
            // 供应商分类 字典
            this.getDicts("sys_supplier_type").then((res) => {
                if (res.code === 200) {
                    this.classificationOptions = res.data.map((item) => {
                        return {
                            value: item.dictCode,
                            label: item.dictLabel,
                        };
                    });
                }
            });
            // 供应类型 字典
            this.getDicts("sys_supplier_classify").then((res) => {
                if (res.code === 200) {
                    this.supplyCategoryOptions = res.data.map((item) => {
                        return {
                            value: item.dictCode,
                            label: item.dictLabel,
                        };
                    });
                }
            });
            // 供应商等级 字典
            this.getDicts("sys_supplier_level").then((res) => {
                if (res.code === 200) {
                    this.levelOptions = res.data.map((item) => {
                        return {
                            value: item.dictCode,
                            label: item.dictLabel,
                        };
                    });
                }
            });
            // 公司规模
            this.getDicts("company_size").then((res) => {
                if (res.code === 200) {
                    this.companySizeOptions = res.data.map((item) => {
                        return {
                            value: item.dictCode,
                            label: item.dictLabel,
                        };
                    });
                }
            });
            // 公司性质
            this.getDicts("company_nature").then((res) => {
                if (res.code === 200) {
                    this.companyNatureOptions = res.data.map((item) => {
                        return {
                            value: item.dictCode,
                            label: item.dictLabel,
                        };
                    });
                }
            });
            // 公司类别
            this.getDicts("company_type").then((res) => {
                if (res.code === 200) {
                    this.companyCategoryOptions = res.data.map((item) => {
                        return {
                            value: item.dictCode,
                            label: item.dictLabel,
                        };
                    });
                }
            });
            // 税分类
            this.getDicts("SFL_SYS").then((res) => {
                if (res.code === 200) {
                    this.taxTypeOptions = res.data.map((item) => {
                        return {
                            value: item.dictCode,
                            label: item.dictLabel,
                        };
                    });
                }
            });
            // 经营类型
            this.getDicts("sys_run_type").then((res) => {
                if (res.code === 200) {
                    this.manageTypeOptions = res.data.map((item) => {
                        return {
                            value: item.dictCode,
                            label: item.dictLabel,
                        };
                    });
                }
            });
            // 发票类型
            this.getDicts("FPLX_SYS").then((res) => {
                if (res.code === 200) {
                    this.invoiceTypeOptions = res.data.map((item) => {
                        return {
                            value: item.dictCode,
                            label: item.dictLabel,
                        };
                    });
                }
            });
        },
    },
    created() {
        // 查询国家
        this.getNation();
        this.initDefaultData();
    },
};
</script>
<style lang="scss" scoped>
// .add {
//   padding: 15px;
// }
.panel-title {
    font-size: 18px;
    color: #37474f;
    font-weight: 500;
    text-shadow: rgba(0, 0, 0, 0.15) 0 0 1px;
}

::v-deep .el-form-item__content {
    margin-left: 0;
}

.main-responsible {
    font-size: 14px;
    font-weight: 550;
    color: #263238;
    position: relative;
    text-indent: 15px;
}
::v-deep .el-table td.el-table__cell div {
    overflow: visible;
}

::v-deep .el-table td.el-table__cell {
    padding-bottom: 20px;
}
</style>
